package setting

import (
	"github.com/go-ini/ini"
	"log"
	"time"
)

var (
	Cfg *ini.File

	RunMode string

	HTTPPort     int
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	PageSize  int
	JwtSecret string
)

func init() {
	var err error
	Cfg, err = ini.Load("conf/app.ini")
	if err != nil {
		log.Fatal("Fail to read file:", err)
	}
	RunMode = Cfg.Section("").Key("RUN_MODE").MustString("debug")
	loadApp()
	loadServer()
}

func loadApp() {
	PageSize = Cfg.Section("app").Key("PAGE_SIZE").MustInt()
	JwtSecret = Cfg.Section("app").Key("JWT_SECRET").MustString("!@)*#)!@U#@*!@!)")
}

func loadServer() {
	HTTPPort = Cfg.Section("server").Key("HTTP_PORT").MustInt(8000)
	WriteTimeout = time.Duration(Cfg.Section("server").Key("WRITE_TIMEOUT").MustInt(60)) * time.Second
	ReadTimeout = time.Duration(Cfg.Section("server").Key("READ_TIMEOUT").MustInt(60)) * time.Second
}
